<template>

  <div>
    <!-- <h3>policeDriverList</h3> -->
    <!-- 驾驶员管理 -->
    <el-table
      :data="driverList"
      style="width: 100%"
      :default-sort="{ prop: 'date' }"
    >
     <el-table-column label="序号" type="index" prop="index" sortable>
       <template slot-scope="scope">
         <span>{{ (page.current - 1) * page.size + scope.$index + 1 }}</span>
       </template>
     </el-table-column>

      <el-table-column label="身份证号">
        <template slot-scope="scope">
          <span style="margin-left: 20px">{{ scope.row.cardId}}</span>
        </template>
      </el-table-column>

     <el-table-column label="电话">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="警队地址">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.address }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生日">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{formatTimer(scope.row.birthday)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份证签发机关">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.department }}</span>
        </template>
      </el-table-column>
      <el-table-column label="名字">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.state }}</span>
        </template>
      </el-table-column>
      <el-table-column label="有效期" prop="date" sortable>
        <template slot-scope="scope">
          <span>{{ formatTimer(scope.row.validity) }}</span>
        </template>
      </el-table-column>


    </el-table>
    <el-pagination
      :spam="20"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.current"
      :page-sizes="[3, 5, 10, 50]"
      :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
      style="text-align: center"
    >
    </el-pagination>
  </div>
</template>

<script>
  import Url from "@/util/URLUtil";
  export default{
    name:"AllDriverList",
    data() {
      return{
        driverList: [],
        page: {
           current: 1, //当前页
           size: 5, //每页数据条数
           pages: 0, //总页数
           total: 0, //总数据条数
        },
      }
    },
    methods:{
      //初始化表格数据
      initDriverListTable(){
        var mythis=this;
        $.ajax({
          url:Url.url+"/aqi/selectDriverByCardId",
          type:"get",
          contentType: "application/json",
          data:{current: mythis.page.current, size: mythis.page.size },
          success(rs){
            console.log("--"+rs);
            mythis.driverList=rs.records;
            mythis.page.total=rs.total;
            mythis.page.size=rs.size;
            mythis.page.current=rs.current;
            mythis.page.pages=rs.pages;
          }
        });
      },
      //修改每页尺寸
      handleSizeChange(val) {
        this.page.size = val;
        this.page.current = 1;
        this.initDriverListTable();
      },
      //修改当前页
      handleCurrentChange(val) {
        this.page.current = val;
        this.initDriverListTable();
      },
      //日期格式化工具
      formatTimer(value) {
        let date = new Date(value);
        let y = date.getFullYear();
        let MM = date.getMonth() + 1;
        MM = MM < 10 ? "0" + MM : MM;
        let d = date.getDate();
        d = d < 10 ? "0" + d : d;
        let h = date.getHours();
        h = h < 10 ? "0" + h : h;
        let m = date.getMinutes();
        m = m < 10 ? "0" + m : m;
        let s = date.getSeconds();
        s = s < 10 ? "0" + s : s;
        return y + "-" + MM + "-" + d + " " + h + ":" + m;
      },

    },
    mounted() {
        this.initDriverListTable();
    }
  }
</script>

<style>
</style>
